@extends('manage.layout')

@section('content')
    <section class="content-header">
        <h1>
            项目列表
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Project</a></li>
            <li class="active">Project List</li>
        </ol>
        <div class="input-group margin">
            <form action="{{ url('project') }}" method="get">
                {{--{{ csrf_field() }}--}}
                <select style="width: 150px" id="sel"  name="type" class="form-control" onchange="select()">
                    @foreach($searchtype as $value)
                        <option value="{{ $value['id'] }}">{{ $value['searchtype'] }}</option>
                    @endforeach
                </select>

                <div style="float: left" id="form">
                    <input id="datepicker" style="width: 200px"  name="param" type="text" class="form-control">
                    {{--<input style="width: 200px" type="text" name="param" class="form-control" id="datepicker">--}}
                </div>
                <input  type="submit" class="btn btn-info btn-flat" value="Go!">
            </form>
            <script>
                function select() {
                    var val = $('#sel option:selected').val();
                    console.log(val);
                    if(val == 2) {
                        $('#datepicker').datepicker({
                            autoclose: true,
                            format: 'yyyy-mm-dd'
                        });
                    }
                    else{
                        $('#datepicker').datepicker('remove');
//                        $('#datepicker').datepicker('remove');
//                        $('#form').html('<input style="width: 200px" id="data" name="param" type="text" class="form-control">');
                    }
                }
            </script>
        </div>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title">内容</h3>
                        <span style="float:right;color: #bbb">共{{$count}}条结果</span>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <table class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>权重</th>
                                <th>创建时间</th>
                                <th>
                                    更新时间&nbsp;&nbsp;
                                    <a href="/project?type={{$search}}&param={{$param}}&orderBy=1"><i class="fa fa-arrow-up"></i></a>&nbsp;&nbsp;
                                    <a href="/project?type={{$search}}&param={{$param}}&orderBy=2"><i class="fa fa-arrow-down"></i></a>
                                </th>
                                <th>项目名称</th>
                                <th>客户名称</th>
                                <th>等级</th>
                                {{--<th>产品</th>--}}
                                {{--<th>项目详情</th>--}}
                                {{--<th>预估价格</th>--}}
                                <th>客户报价</th>
                                <th>项目来源</th>
                                <th>来源编号</th>
                                <th>阶段</th>
                                {{--<th>图片管理</th>--}}
                                {{--<th>附件管理</th>--}}
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($project as $p)
                                <tr>
                                    <td>{{ $p['id'] }}</td>
                                    <td>{{ $p['rank'] }}</td>
                                    <td>{{ $p['create_time'] }}</td>
                                    <td>{{ $p['update_time'] }}</td>
                                    <td>{{ $p['name'] }}</td>
                                    <td>{{ App\Model\Client::find($p['client_id'])['company'] }}</td>
                                    <td>
                                        @if($p['grade'] ==0 )一般
                                        @elseif($p['grade'] ==1)重要
                                        @endif
                                    </td>
                                    {{--<td>{{ App\Model\Product::find($p['product_id'])['name'] }}</td>--}}
                                    {{--<td>{{ $p['details'] }}</td>--}}
                                    {{--<td>{{ $p['future_price'] }}</td>--}}
                                    <td>{{ $p['client_price'] }}</td>
                                    <td>
                                        @if($p['origin'] ==0 )独立
                                        @elseif($p['origin'] ==1)在线
                                        @elseif($p['origin'] ==2)介绍
                                        @endif
                                    </td>
                                    <td>{{ $p['origin_id'] }}</td>
                                    <td>
                                        @if($p['stage'] ==0 )初步洽谈
                                        @elseif($p['stage'] ==1)二次洽谈
                                        @elseif($p['stage'] ==2)需求确定
                                        @elseif($p['stage'] ==3)提案/报价
                                        @elseif($p['stage'] ==4)签单准备
                                        @endif
                                    </td>
                                    {{--<td>图片管理</td>--}}
                                    {{--<td>附件管理</td>--}}
                                    {{--<td>{{ $p['remark'] }}</td>--}}
                                    <td>
                                        <a href="/project?searchtype=100&param={{$p['status']}}">
                                            @if($p['status'] == 0)<label>已停止</label>
                                            @else<label>进行中</label>
                                            @endif
                                        </a>
                                    </td>
                                    <td>
                                        <a class="btn btn-info btn-xs" href="/project/project_detail/{{ $p['id'] }}">项目详情</a>
                                        @if($p['status'] == 1)
                                            <a class="btn btn-warning btn-xs" href="javascript:projectStatus('{{ $p['id'] }}',0)">停止<a>
                                        @elseif($p['status'] == 0)
                                            <a class="btn btn-success btn-xs" href="javascript:projectStatus('{{ $p['id'] }}',1)">进行<a>
                                        @endif
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                    <!-- /.box-body -->
                    <div style="text-align: center;">
                        {{ $project->appends(['searchtype'=>$search,'param'=>$param,'count'=>$count])->links() }}
                    </div>
                </div>
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
@stop
@section('script')
    <script>

        //禁用,启用
        function projectStatus(id,status) {
            console.log(id);
            console.log(status);
            $.ajax({
                url: '/project/projectStatus',
                type: "GET",
                data: {id:id,status:status},
                dataType: "json",
                success: function(res) {
                    console.log(res);
                    if(res.code == 100) {
                        layer.msg(res.msg, {time:1500, icon:6});
                        window.location.href=window.location.href;
                    }
                    else {
                        layer.msg(res.msg, {time:1500, icon:5});
                    }
                }
            });
        }
    </script>
@stop